requireNonNull

open fun <T> requireNonNull(@Nullable obj: T): T(source)

Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:

public Foo(Bar bar) {
    this.bar = Objects.requireNonNull(bar);
}

Return

obj if not null

Parameters

obj

the object reference to check for nullity

<T>

the type of the reference

Throws

if obj is null


open fun <T> requireNonNull(@Nullable obj: T, @NonNull message: String): T(source)

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:

public Foo(Bar bar, Baz baz) {
    this.bar = Objects.requireNonNull(bar, "bar must not be null");
    this.baz = Objects.requireNonNull(baz, "baz must not be null");
}

Return

obj if not null

Parameters

obj

the object reference to check for nullity

message

detail message to be used in the event that a NullPointerException is thrown

<T>

the type of the reference

Throws

if obj is null